import { stringify } from 'qs';
import request from '@/utils/request';
import { async } from 'q';

//告警列表
export async function queryWarnings(params) {
	let url = '/iot/dmp/v1/warning/list'
	return request(url, {
		method: 'POST',
		body: {
			...params
		},
	});
}
//告警详情
export async function getWarningDetail(params) {
	return request(`/iot/dmp/v1/device/${params.device_id}`, {
		method: 'get'
	})
}
//部门树
export async function getDeptTree(params) {
	return request('/iot/dmp/v1/depts/tree', {
		method: 'POST',
		body: {
			...params
		}
	})
}

//工单详情
export async function getDeviceOrder(params) {
	//${params.did}
	return request(`/iot/workflow/v1/workflow/select-task/${params.did}`, {
		method: 'get'
	})
}

//动态记录
export async function getEventLog(params) {
	return request('/iot/dmp/v1/taskLog/list', {
		method: 'POST',
		body: {
			...params
		}
	})
}

//流程图
export async function getWorkflow(params) {
  const url = `/iot/workflow/v1/workflow/generateImage/${params.process_instance_id}`;
  return request(url, {
    reuqestImage :true,
    method: 'get'
  })
}

//部门下的用户
export async function getUser(params) {
	return request('/iot/dmp/v1/users/list', {
		method: 'POST',
		body: {
			...params,
			is_child_only: '1'
		}
	})
}

export async function createWorkflow(params) {
	return request('/iot/workflow/v1/workflow/create', {
		method: 'POST',
		body: {
			...params
		}
	})
}

export async function taskAccept(params) {
	console.log(params)
	return request(`/iot/workflow/v1/workflow/apply`, {
		method: 'POST',
		body: {
			...params
		}
	})
}

export async function uploadHandleRes(params) {
	return request('/iot/workflow/v1/workflow/complete', {
		method: 'fileUpload',
		reMethod: 'POST',
		body: {
			...params
		},
	}
	);
}

export async function cancelWarning(params) {
	return request(`/iot/dmp/v1/warning-close/${params.device_id}`)
}
